<html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- jQuery -->
    <script type="text/javascript" src="../js/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="../js/jquery-3.3.1.js"></script>

    <!-- Bootstrap -->
    <link href="../bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="../bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

    <style type="text/css">
        html {
            overflow-x: hidden;
            overflow-y: auto;
        }

        #title {
            background-color: cornflowerblue;
        }

        .row-margin-top {
            margin: 10px;
        }

        #main {
            display: table;
            width: auto;
            margin-left: auto;
            margin-right: auto;
            margin-top: 100px;
        }

        #footer {
            text-align: center;
            font-size: 20px;
            position: relative;
            bottom: 10px;
        }

        p {
            font-family: 微软雅黑;
            font-size: large;
        }

        th {
            text-align: center;
        }

        td {
            text-align: center;
        }

        #myInfo {
            font-family: 微软雅黑;
            font-size: large;
            color: blue;
        }

        #off {
            margin-top: 10px;
            font-family: 微软雅黑;
            color: black;
        }

    </style>

</head>

<body>


<!--页面主体-->
<!--主体-->
<div class="container-fluid">
    <div class="row " id="title">
        <div class="col-md-1 row-margin-top">
            <!--            <button id="back" class="btn btn-info btn-default btn-lg active" ><span class="glyphicon glyphicon-align-justify" aria-hidden="true"></span>&nbsp;返回</button>-->
            <a href="playView.html">
                <button class="btn btn-info btn-lg active"><span class="glyphicon glyphicon-film"
                                                                 aria-hidden="true"></span>&nbsp;首页
                </button>
            </a>
        </div>

        <div class="col-md-5 col-md-offset-3">
            <h1>欢 迎 光 临 T T M S 影 院</h1>
        </div>

        <div class="col-md-1 col-md-offset-2 row-margin-top">
            <a href="myInfo.html">
                <button id="myInfo" class="btn btn-link btn-lg "><span class="glyphicon glyphicon-user"
                                                                       aria-hidden="true"></span>&nbsp;
                </button>
            </a>
        </div>

        <div class="col-md-1 row-margin-top">
            <a href="../index.html">
                <button id="off" class="btn btn-link  "><span class="glyphicon  glyphicon-off"
                                                              aria-hidden="true"></span>&nbsp;注销
                </button>
            </a>
        </div>

    </div>

    <div class="row row-margin-top">

        <div class="col-md-2 col-md-offset-2">
            <img src="" class="img-rounded" width="400px" height="310px" id="picture">
        </div>
        <div class="col-md-5 col-md-offset-1">
            <div class="row row-margin-top">
                <div class="col-md-12 ">
                    <form class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">电影名称</label>
                            <div class="col-sm-10">
                                <p class="form-control-static" id="playName"></p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">电影时长</label>
                            <div class="col-sm-10">
                                <p class="form-control-static" id="playLength"></p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">电影类型</label>
                            <div class="col-sm-10">
                                <p class="form-control-static" id="playType"></p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">电影简介</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" rows="6" id="playDescription"
                                          readonly="readonly"></textarea>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="row row-margin-top" id="main">
        <div class="col-md-4 col-md-offset-5">
            <h1>演出计划</h1>
        </div>

        <div class="col-md-12">
            <table id="schedule_table" class="table table-bordered table-striped">
                <thead>
                <tr>
                    <th>电影名称</th>
                    <th>演出厅名称</th>
                    <th>开始时间</th>
                    <th>价格(元)</th>
                    <th>操作</th>
                </tr>
                <tr id="tr_details">
                    <td id="name"></td>
                    <td id="studio"></td>
                    <td id="time"></td>
                    <td id="price"></td>
                    <td id="selectSeat">
                        <button class="btn btn-info btn-sm edit_btn"><span class="glyphicon glyphicon-pencil">购票</span>
                        </button>
                    </td>
                </tr>
                </thead>
                <tbody>

                </tbody>
            </table>

        </div>
    </div>

    <!--页脚-->
    <div class="row">
        <div id="footer" class="col-md-12">
            <hr style="height:1px;border:none;border-top:1px solid #555555;"/>
            <span>CopyRight@2020</span>
        </div>
    </div>
</div>
</body>

<script>

    $(function () {
        //给myInfo添加用户信息
        $.ajax({
            type: "post",
            url: "../play/userLogin",
            success: function (userLogin) {


                var uri = location.search;
                //解决乱码
                var playName = decodeURIComponent(uri).split("=")[1];
                //影片的详细信息展示
                $.ajax({
                    url: "../play/filmDetails",
                    type: "post",
                    data: {"playName": playName},
                    success: function (data) {
                        $("#picture").prop("src", "../images/" + data.playImage + ".jpg")
                        $("#playName").append(data.playName)
                        $("#playLength").append(data.playLength)
                        $("#playType").append(data.playType)
                        $("#playDescription").append(data.playDescription)
                    },
                    dataType: "json"
                })


                //查询是否有演出计划
                $.ajax({
                    data: {"playName": playName},
                    type: "post",
                    url: "../schedule/findSchedule",
                    success: function (data) {
                        if (data == null) {
                            location.href = "http://localhost:8080/cinema/pages/playView.html"
                            alert("本片还未上线！")
                        }
                        $("#name").html(data.play.playName)
                        $("#studio").html(data.studio.studioName)
                        $("#time").html(data.startTime)
                        $("#price").html(data.schedulePrice)
                    },
                    dataType: "json"
                })
                $(".edit_btn").click(function () {
                    var studio = document.getElementById("studio").innerHTML;
                    $.ajax({
                        url: "../searchSeat/buyTickets",
                        data: {"playName": playName},
                        type: "post",
                        success: function (data) {

                            //空：票售罄
                            if (data == null) {
                                alert("票已售罄！")
                                location.href = "http://localhost:8080/cinema/pages/playView.html";
                                return;
                            } else {
                                if (confirm("确定要购票吗? 片名：" + playName + " 票号：" + data.ticketId + " 票价：" + data.ticketPrice + " 播出时间：" + data.ticketTime) == false) {
                                    return;
                                }
                                $.ajax({
                                    url: "../searchSeat/confirm",
                                    data: {"ticketId": data.ticketId, "userId": userLogin.userId},
                                    type: "post",
                                    success: function (data) {
                                        alert(data)
                                        location.href = "http://localhost:8080/cinema/pages/playView.html"

                                    },
                                    dataType: "json"
                                })
                            }


                        },
                        dataType: "json"
                    })
                })


            },
            dataType: "json"
        })


    })


</script>
</html>